package com.example.controller;

import com.example.model.dto.LoginFormDTO;
import com.example.model.dto.Result;
import com.example.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @program: backed
 * @author: zk
 * @create: 2023-03-23 19:15
 **/
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {
    @Resource
    private IUserService userService;

    /**
     * 登录
     *
     * @param loginForm
     * @return
     */
    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginFormDTO loginForm, HttpServletRequest request) {
        return userService.login(loginForm,request);
    }


    /**
     * 注册
     *
     * @param loginForm
     * @return
     */
    @ApiOperation("注册")
    @PostMapping("/register")
    public Result register(@RequestBody LoginFormDTO loginForm) {
        return userService.register(loginForm);
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    @ApiOperation("获取用户信息")
    @GetMapping("")
    public Result getUserMsg(HttpServletRequest request) {
        return userService.getUserMsg(request);
    }

    /**
     * 退出登录
     * @return
     */
    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public Result logout(HttpServletRequest request) {
        return userService.logout(request);
    }

}
